import { drugs } from "@/api/MedicalExamination";
import { BasicProTable, useProTable } from "@/components/ViewComponents/proTable";
import { Button } from "antd";

const index = () => {
	const dataSource = [
		{
			key: 0,
			name: "Edward King 0",
			age: "32",
			address: "London, Park Lane no. 0"
		}
	];
	const defaultColumns = [
		{
			title: "name",
			dataIndex: "name",
			editable: true,
			width: "20%",
			type: "ApiSelect",
			componentProps: {
				api: drugs,
				labelField: "drugName",
				valueField: "drugId"
			}
		},
		{
			title: "age",
			dataIndex: "age",
			editable: true
		},
		{
			title: "address",
			dataIndex: "address"
		},
		{
			title: "操作",
			render: (_, obj) => {
				return <Button onClick={onDelete(obj)}>{t("felix_ui.delete")}</Button>;
			}
		}
	];

	const [register, { submit, handleAdd, handleDelete }] = useProTable({
		dataSource,
		defaultColumns
	});
	const onSubmit = async () => {
		const values = await submit();
		console.log(values);
	};
	const onAdd = () => {
		handleAdd({
			key: new Date().getTime(),
			name: "Edward King 0",
			age: "32",
			address: "London, Park Lane no. 0"
		});
	};
	const onDelete = obj => () => {
		handleDelete(obj.key);
	};
	return (
		<div>
			<BasicProTable register={register}></BasicProTable>
			<Button onClick={onSubmit}>提交</Button>
			<Button onClick={onAdd}> 添加</Button>
		</div>
	);
};

export default index;
